<!DOCTYPE html>
<html>

<head>

    {include file="Public/header"}
    <style>
        .row {
            border: 1px solid #ccc;
            margin: 0 auto;
        }

        .agencyM_table tr th {
            text-align: center;
        }
    </style>
</head>

<body class="white-bg" style="color:#333;padding:0px;">
<div class="container" style="width: 100%;padding: 0">
    <table class="table">
        <tr>
            <td>导购员：</td>
            <td colspan="2">
                <div style="float:left;">
                    <div class="form-group" >
                        <div class="input-group">
                            <input id="xgry" type="text" placeholder="请输入关键字或空格查询"
                                   class="form-control" value="" style="min-width: 300px;width: 300px">
                            <div class="input-group-btn">
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>

                <a href="javascript:;" id="select_xgry" class="btn btn-primary btn-sm" style="float:left;">选择</a>
            </td>
        </tr>
        <tr>
            <td>您选定的导购：</td>
            <td>
                <div class="duoxuan">

                </div>
            </td>
            <td>
                <a href="">清空</a>
            </td>
        </tr>
        <tr><td colspan="3">
            <font color="red">温馨提示：点击确定后将会把当前网点添加至导购的所属网点中(从网点)。</font>
        </td></tr>
    </table>
</div>
    <!-- 全局js -->
    {include file="Public/footer"}
    <!-- <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> -->
    <script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
    <script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>
<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
    <script>
        $(document).ready(function () {

            //弹出选择相关人员
            $('#select_xgry').on('click',function () {
                var _this = this
                var index = layer.getFrameIndex(window.name)
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    maxmin:true,
                    btn:'确定',
                    btnAlign:'c',
                    content:'{:url("open/employee")}',
                    yes:function (i,o) {
                        var a = $(o).find('iframe').contents()
                        var data = a.find('#data')
                        data = data.val()
                        data = JSON.parse(data)
                        var bool = false
                        for(var j=0;j<data.length;j++){
                            $(_this).closest('tr').find('.duoxuan .ren').each(function (idx, o) {
                                if ($(this).data('id') == data[j].id) {
                                    bool = true;
                                }
                            })
                            if (bool == false)
                                $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + data[j].id + '">' + data[j].title + '<input type="hidden" name="xm[]" value="' + data[j].id + '"><span class="close">×</span></span>')
                        }
                        layer.close(i)
                    }
                })
                return  false
            })

            //删除单个选定
            $('body').on('click','.duoxuan .close',function () {

                $(this).closest('.ren').remove()
            })
            //相关人员
            $("#xgry").bsSuggest({
                url:"{:url('Bs/employee')}",
                effectiveFields: ["id", "title"],
                searchFields: [ "title"],
                effectiveFieldsAlias: {title: "名称"},
                ignorecase: true,
                showHeader: true,
                showBtn: false,     //不显示下拉按钮
                delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                idField: "id",
                keyField: "title",
                clearable: true
            }).on('onDataRequestSuccess', function (e, result) {
                console.log('onDataRequestSuccess: ', result);
            }).on('onSetSelectValue', function (e, keyword, data) {
                $(this).val('')
                var bool = false
                $(this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                    if ($(this).data('id') == keyword.id) {
                        bool = true;
                    }
                })
                if (bool == false)
                    $(this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + keyword.id + '">' + keyword.key + '<input type="hidden" name="xm[]" value="' + keyword.id + '"><span class="close">×</span></span>')
                //console.log('onSetSelectValue: ', keyword, data);
            }).on('onUnsetSelectValue', function () {
                console.log("onUnsetSelectValue");
            });

        })
    </script>
</body>

</html>